<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: PasswordsController</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">PasswordsController</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/app/controllers/passwords_controller_rb.html">
                app/controllers/passwords_controller.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="ApplicationController.html">
                ApplicationController
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000057">create</a>&nbsp;&nbsp;
      <a href="#M000058">edit</a>&nbsp;&nbsp;
      <a href="#M000056">new</a>&nbsp;&nbsp;
      <a href="#M000059">update</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000057" class="method-detail">
        <a name="M000057"></a>

        <div class="method-heading">
          <a href="#M000057" class="method-signature">
          <span class="method-name">create</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Forgot password action
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000057-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000057-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/passwords_controller.rb, line 10</span>
10:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>    
11:     <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">post?</span>
12:   <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find_for_forget</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:email</span>])
13:       <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">forgot_password</span>
14:       <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">save</span>      
15:       <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:notice</span>] = <span class="ruby-value str">&quot;A password reset link has been sent to your email address.&quot;</span> 
16:     <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">login_path</span>
17:     <span class="ruby-keyword kw">else</span>
18:       <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:notice</span>] = <span class="ruby-value str">&quot;Could not find a user with that email address.&quot;</span> 
19:       <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'new'</span>
20:     <span class="ruby-keyword kw">end</span>  
21:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000058" class="method-detail">
        <a name="M000058"></a>

        <div class="method-heading">
          <a href="#M000058" class="method-signature">
          <span class="method-name">edit</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Action triggered by clicking on the /reset_password/:id link recieved via
email Makes sure the id code is included Checks that the id code matches a
user in the database Then if everything checks out, shows the password
reset fields
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000058-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000058-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/passwords_controller.rb, line 27</span>
27:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">edit</span>
28:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>].<span class="ruby-identifier">nil?</span> 
29:       <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'new'</span>
30:       <span class="ruby-keyword kw">return</span>
31:     <span class="ruby-keyword kw">end</span>
32:     <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_password_reset_code</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]
33:     <span class="ruby-identifier">raise</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">nil?</span>
34:   <span class="ruby-keyword kw">rescue</span>
35:     <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-value str">&quot;Invalid Reset Code entered.&quot;</span> 
36:     <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:notice</span>] = <span class="ruby-value str">&quot;Sorry - That is an invalid password reset code. Please check your code and try again. (Perhaps your email client inserted a carriage return?)&quot;</span> 
37:     <span class="ruby-comment cmt">#redirect_back_or_default('/')</span>
38:     <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">new_user_path</span>
39:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000056" class="method-detail">
        <a name="M000056"></a>

        <div class="method-heading">
          <a href="#M000056" class="method-signature">
          <span class="method-name">new</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Enter email address to recover password
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000056-source">
<pre>
   <span class="ruby-comment cmt"># File app/controllers/passwords_controller.rb, line 6</span>
6:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new</span>
7:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000059" class="method-detail">
        <a name="M000059"></a>

        <div class="method-heading">
          <a href="#M000059" class="method-signature">
          <span class="method-name">update</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reset password action /reset_password/:id Checks once again that an id is
included and makes sure that the password field isn&#8216;t blank
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000059-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000059-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/passwords_controller.rb, line 43</span>
43:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update</span>
44:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>].<span class="ruby-identifier">nil?</span> 
45:       <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'new'</span>
46:       <span class="ruby-keyword kw">return</span>
47:     <span class="ruby-keyword kw">end</span>
48:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:password</span>].<span class="ruby-identifier">blank?</span> 
49:       <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:notice</span>] = <span class="ruby-value str">&quot;Password field cannot be blank.&quot;</span>
50:       <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'edit'</span>, <span class="ruby-identifier">:id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]
51:       <span class="ruby-keyword kw">return</span>
52:     <span class="ruby-keyword kw">end</span>
53:     <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_password_reset_code</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]
54:     <span class="ruby-identifier">raise</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">nil?</span>
55:     <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@user</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:password</span>]
56:       <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:password</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:password_confirmation</span>])
57:       <span class="ruby-comment cmt">#Uncomment and comment lines with @user to have the user logged in after reset - not recommended</span>
58:         <span class="ruby-comment cmt">#self.current_user = @user #for the next two lines to work</span>
59:         <span class="ruby-comment cmt">#current_user.password_confirmation = params[:password_confirmation]</span>
60:         <span class="ruby-comment cmt">#current_user.password = params[:password]</span>
61:         <span class="ruby-comment cmt">#@user.reset_password</span>
62:     <span class="ruby-comment cmt">#flash[:notice] = current_user.save ? &quot;Password reset&quot; : &quot;Password not reset&quot; </span>
63:     <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">password_confirmation</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:password_confirmation</span>]
64:     <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">password</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:password</span>]
65:     <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">reset_password</span>        
66:     <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:notice</span>] = <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">save</span> <span class="ruby-value">? </span><span class="ruby-value str">&quot;Password reset.&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;Password not reset.&quot;</span>
67:       <span class="ruby-keyword kw">else</span>
68:         <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:notice</span>] = <span class="ruby-value str">&quot;Password mismatch.&quot;</span> 
69:         <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'edit'</span>, <span class="ruby-identifier">:id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]
70:       <span class="ruby-keyword kw">return</span>
71:       <span class="ruby-keyword kw">end</span>  
72:       <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">login_path</span> 
73:   <span class="ruby-keyword kw">rescue</span>
74:     <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-value str">&quot;Invalid Reset Code entered&quot;</span> 
75:     <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:notice</span>] = <span class="ruby-value str">&quot;Sorry - That is an invalid password reset code. Please check your code and try again. (Perhaps your email client inserted a carriage return?)&quot;</span> 
76:     <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">new_user_path</span>
77:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>